<template>
  <div style=" width: 110%; margin: auto;">
    <h3>业务活动表</h3>
    <h4>（截止{{year}}年12月31日） 单位：元</h4>
<!--    <span style="color:red;">*没有则填0</span>-->
    <el-row style="margin-top: 10px;">
      <el-col :span="24">
        <el-table :header-cell-style="{background: '#F0F5FA',color: '#333333'}" :data="listForm">
          <el-table-column prop="fieldSort" label="行次" align="center" width="50"/>
          <el-table-column prop="assetTermName" label="项目" align="center">
            <template #default="scope">
              <span>{{scope.row.assetTermName}}</span>
            </template>
          </el-table-column>

          <el-table-column label="上年末数" align="center">
            <el-table-column  prop="upEndBalanceUnrestricted" label="非限定性" align="center">
              <template #default="scope">
                <el-input :precision="2" @input="upEndBalanceUnrestrictedInput()" v-show="scope.row.fieldSort != 1 && scope.row.fieldSort != 10" :disabled="isInputByTitle(scope.row.fieldSort)"  size="small" style="width: 98%;" v-model="scope.row.upEndBalanceUnrestricted" placeholder=""></el-input>
              </template>
            </el-table-column>
            <el-table-column prop="upEndBalanceRestrict" label="限定性" align="center">
              <template #default="scope">
                <el-input :precision="2" @input="upEndBalanceRestrictInput()" v-show="scope.row.fieldSort != 1 && scope.row.fieldSort != 10" :disabled="isInputByTitle(scope.row.fieldSort)"  size="small" style="width: 98%;" v-model="scope.row.upEndBalanceRestrict" placeholder=""></el-input>
              </template>
            </el-table-column>
            <el-table-column prop="upEndBalanceCount" label="合计" align="center">
              <template #default="scope">
                <span v-show="scope.row.fieldSort != 1 && scope.row.fieldSort != 10">{{getTotal(scope.row.upEndBalanceUnrestricted,scope.row.upEndBalanceRestrict)}}</span>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column label="本年累计数" align="center">
            <el-table-column prop="thisYearUnrestricted" label="非限定性" align="center">
              <template #default="scope">
                <el-input :precision="2" @input="thisYearUnrestrictedInput()" v-show="scope.row.fieldSort != 1 && scope.row.fieldSort != 10" :disabled="isInputByTitle(scope.row.fieldSort)"  size="small" style="width: 98%;" v-model="scope.row.thisYearUnrestricted" placeholder=""></el-input>
              </template>
            </el-table-column>
            <el-table-column prop="thisYearRestrict" label="限定性" align="center">
              <template #default="scope">
                <el-input :precision="2" @input="thisYearRestrictInput()" v-show="scope.row.fieldSort != 1 && scope.row.fieldSort != 10" :disabled="isInputByTitle(scope.row.fieldSort)"  size="small" style="width: 98%;" v-model="scope.row.thisYearRestrict" placeholder=""></el-input>
              </template>
            </el-table-column>
            <el-table-column prop="thisYearCount" label="合计" align="center">
              <template #default="scope">
                <span v-show="scope.row.fieldSort != 1 && scope.row.fieldSort != 10">{{getTotal(scope.row.thisYearUnrestricted,scope.row.thisYearRestrict)}}</span>
              </template>
            </el-table-column>
          </el-table-column>
        </el-table>
      </el-col>
    </el-row>
  </div>
</template>
<script>
import {getTableInfoByPage, mfSaveBusiness} from "@/views/yearCheck/ykb/mf/mf";

export default {
  data() {
    return {
      year:localStorage.getItem('examineYear'),
      listForm:[{
          assetTerm:'',//项目id
          assetTermName:'',//项目名称
          creditCode:localStorage.getItem("creditCode"),//统一社会信用代码
          examineYear:localStorage.getItem("examineYear"),//审查年度
          fieldDirectory:'',//字段目录
          fieldSort:'',//行次
          id:'',//业务活动id
          organizationBaseId:'1',//社团组织id
          thisYearCount:'',//本本年累计合计
          thisYearRestrict:'',//本年累计限定
          thisYearUnrestricted:'',//年累计非限定
          upEndBalanceCount:'',//上年末数合计
          upEndBalanceRestrict:'',//上年末数非限定性
          upEndBalanceUnrestricted:'',//上年末数非限定性
        }
      ]
    };
  },

  created() {

  },
  methods: {
    upEndBalanceUnrestrictedInput(){
      this.listForm[8].upEndBalanceUnrestricted = this.getStr(this.listForm[1].upEndBalanceUnrestricted) + this.getStr(this.listForm[2].upEndBalanceUnrestricted) +
        this.getStr(this.listForm[3].upEndBalanceUnrestricted) + this.getStr(this.listForm[4].upEndBalanceUnrestricted) + this.getStr(this.listForm[5].upEndBalanceUnrestricted) +
        this.getStr(this.listForm[6].upEndBalanceUnrestricted) + this.getStr(this.listForm[7].upEndBalanceUnrestricted);
      this.listForm[18].upEndBalanceUnrestricted = this.getStr(this.listForm[11].upEndBalanceUnrestricted) + this.getStr(this.listForm[12].upEndBalanceUnrestricted) +
        this.getStr(this.listForm[13].upEndBalanceUnrestricted) + this.getStr(this.listForm[14].upEndBalanceUnrestricted) + this.getStr(this.listForm[15].upEndBalanceUnrestricted) +
        this.getStr(this.listForm[16].upEndBalanceUnrestricted) + this.getStr(this.listForm[17].upEndBalanceUnrestricted);
      this.listForm[10].upEndBalanceUnrestricted = this.listForm[18].upEndBalanceUnrestricted;
      this.listForm[20].upEndBalanceUnrestricted = this.getStr(this.listForm[8].upEndBalanceUnrestricted) - this.getStr(this.listForm[18].upEndBalanceUnrestricted);
    },
    upEndBalanceRestrictInput(){
      this.listForm[8].upEndBalanceRestrict = this.getStr(this.listForm[1].upEndBalanceRestrict) + this.getStr(this.listForm[2].upEndBalanceRestrict) +
        this.getStr(this.listForm[3].upEndBalanceRestrict) + this.getStr(this.listForm[4].upEndBalanceRestrict) + this.getStr(this.listForm[5].upEndBalanceRestrict) +
        this.getStr(this.listForm[6].upEndBalanceRestrict) + this.getStr(this.listForm[7].upEndBalanceRestrict);
      this.listForm[18].upEndBalanceRestrict = this.getStr(this.listForm[11].upEndBalanceRestrict) + this.getStr(this.listForm[12].upEndBalanceRestrict) +
        this.getStr(this.listForm[13].upEndBalanceRestrict) + this.getStr(this.listForm[14].upEndBalanceRestrict) + this.getStr(this.listForm[15].upEndBalanceRestrict) +
        this.getStr(this.listForm[16].upEndBalanceRestrict) + this.getStr(this.listForm[17].upEndBalanceRestrict);
      this.listForm[10].upEndBalanceRestrict = this.listForm[18].upEndBalanceRestrict;
      this.listForm[20].upEndBalanceRestrict = this.getStr(this.listForm[8].upEndBalanceRestrict) - this.getStr(this.listForm[18].upEndBalanceRestrict);
    },
    thisYearUnrestrictedInput(){
      this.listForm[8].thisYearUnrestricted = this.getStr(this.listForm[1].thisYearUnrestricted) + this.getStr(this.listForm[2].thisYearUnrestricted) +
        this.getStr(this.listForm[3].thisYearUnrestricted) + this.getStr(this.listForm[4].thisYearUnrestricted) + this.getStr(this.listForm[5].thisYearUnrestricted) +
        this.getStr(this.listForm[6].thisYearUnrestricted) + this.getStr(this.listForm[7].thisYearUnrestricted);
      this.listForm[18].thisYearUnrestricted = this.getStr(this.listForm[11].thisYearUnrestricted) + this.getStr(this.listForm[12].thisYearUnrestricted) +
        this.getStr(this.listForm[13].thisYearUnrestricted) + this.getStr(this.listForm[14].thisYearUnrestricted) + this.getStr(this.listForm[15].thisYearUnrestricted) +
        this.getStr(this.listForm[16].thisYearUnrestricted) + this.getStr(this.listForm[17].thisYearUnrestricted);
      this.listForm[10].thisYearUnrestricted = this.listForm[18].thisYearUnrestricted;
      this.listForm[20].thisYearUnrestricted = this.getStr(this.listForm[8].thisYearUnrestricted) - this.getStr(this.listForm[18].thisYearUnrestricted);
    },
    thisYearRestrictInput(){
      this.listForm[8].thisYearRestrict = this.getStr(this.listForm[1].thisYearRestrict) + this.getStr(this.listForm[2].thisYearRestrict) +
        this.getStr(this.listForm[3].thisYearRestrict) + this.getStr(this.listForm[4].thisYearRestrict) + this.getStr(this.listForm[5].thisYearRestrict) +
        this.getStr(this.listForm[6].thisYearRestrict) + this.getStr(this.listForm[7].thisYearRestrict);
      this.listForm[18].thisYearRestrict = this.getStr(this.listForm[11].thisYearRestrict) + this.getStr(this.listForm[12].thisYearRestrict) +
        this.getStr(this.listForm[13].thisYearRestrict) + this.getStr(this.listForm[14].thisYearRestrict) + this.getStr(this.listForm[15].thisYearRestrict) +
        this.getStr(this.listForm[16].thisYearRestrict) + this.getStr(this.listForm[17].thisYearRestrict);
      this.listForm[10].thisYearRestrict = this.listForm[18].thisYearRestrict;
      this.listForm[20].thisYearRestrict = this.getStr(this.listForm[8].thisYearRestrict) - this.getStr(this.listForm[18].thisYearRestrict);
    },
    getStr(str) {
      if (str == null || str == '') {
        str = 0
      } else {
        str = parseFloat(str)
      }
      return str;
    },
    postInfo(){
      for (let i = 0; i < this.listForm.length; i++) {
        this.listForm[i].creditCode = localStorage.getItem("creditCode");
        this.listForm[i].examineYear = localStorage.getItem("examineYear");
        this.listForm[i].organizationBaseId = '1';
        if(this.listForm[i].upEndBalanceUnrestricted != null && this.listForm[i].upEndBalanceUnrestricted != ''){
          this.listForm[i].upEndBalanceUnrestricted = parseFloat(this.listForm[i].upEndBalanceUnrestricted).toFixed(2);
        }
        if(this.listForm[i].upEndBalanceRestrict != null && this.listForm[i].upEndBalanceRestrict != ''){
          this.listForm[i].upEndBalanceRestrict = parseFloat(this.listForm[i].upEndBalanceRestrict).toFixed(2);
        }
        if(this.listForm[i].thisYearRestrict != null && this.listForm[i].thisYearRestrict != ''){
          this.listForm[i].thisYearRestrict = parseFloat(this.listForm[i].thisYearRestrict).toFixed(2);
        }
        if(this.listForm[i].thisYearUnrestricted != null && this.listForm[i].thisYearUnrestricted != ''){
          this.listForm[i].thisYearUnrestricted = parseFloat(this.listForm[i].thisYearUnrestricted).toFixed(2);
        }
        this.listForm[i].upEndBalanceCount = this.getTotal(this.listForm[i].upEndBalanceUnrestricted,this.listForm[i].upEndBalanceRestrict);
        this.listForm[i].thisYearCount = this.getTotal(this.listForm[i].thisYearRestrict,this.listForm[i].thisYearUnrestricted);
      }
      mfSaveBusiness(this.listForm).then(response => {
        this.$message({
          message: '保存业务活动表成功！',
          type: 'success'
        });
        this.getInfo();
      });
    },
    getTotal(a,b){
      if(a == null || a == ''){
        a = 0;
      }
      if(b == null || b == ''){
        b = 0;
      }
      return (parseFloat(a) + parseFloat(b)).toFixed(2);
    },
    getInfo() {
      getTableInfoByPage(19).then(response => {
        this.listForm = JSON.parse(JSON.stringify(response.data).replace(/null/g, '""'));
        if(this.listForm == null || this.listForm.length == 0 || this.listForm.length < 4){
          this.listForm = [];
        }
        // for (let i = 0; i < this.listForm.length; i++) {
        //   if(this.listForm[i].upEndBalanceUnrestricted == null || this.listForm[i].upEndBalanceUnrestricted == ''){
        //     this.listForm[i].upEndBalanceUnrestricted = 0;
        //   }
        //   if(this.listForm[i].upEndBalanceRestrict == null || this.listForm[i].upEndBalanceRestrict == ''){
        //     this.listForm[i].upEndBalanceRestrict = 0;
        //   }
        //   if(this.listForm[i].thisYearUnrestricted == null || this.listForm[i].thisYearUnrestricted == ''){
        //     this.listForm[i].thisYearUnrestricted = 0;
        //   }
        //   if(this.listForm[i].thisYearRestrict == null || this.listForm[i].thisYearRestrict == ''){
        //     this.listForm[i].thisYearRestrict = 0;
        //   }
        //   console.log(this.listForm)
        // }
      });
    },
    isInputByTitle(fieldSort){
      if(fieldSort == 9){
        return true;
      }else if(fieldSort == 11){
        return true;
      }else if(fieldSort == 19){
        return true;
      }else if(fieldSort == 21){
        return true;
      }
      return false;
    }
  }
}
</script>
<style scoped lang="scss">
.el-table {
  --el-table-row-hover-bg-color: rgba(39, 137, 238, 0.1);
  --el-table-border-color:#e0e5f0;
}
:deep(.el-card.is-always-shadow) {
  box-shadow: 0 1px 14px 0 rgba(209, 224, 239, 0.6)
}

/* 拉框选中 */
.el-select-dropdown__item {
  height: 24px;
  line-height: 24px;
  font-size: 12px;
}

/* 鼠标经过下拉框 */
.el-select-dropdown__item:hover {
  height: 24px;
  line-height: 24px;
  font-size: 12px;
}

.el-select-dropdown__item.selected {
  color: #2789EE;
}

.div-bg {
  width: 100%;
  background: #F0F0F0;
  height: 10px;
}

.box-card {
  width: 100%;
  margin-top: 20px;
  padding: 20px;
}

.el-col {
  padding-left: 5px;
}

.divider-title {
  font-weight: bold;
  font-size: 18px;
}

.custom-select .el-select-dropdown {
  max-height: 600px; /* 设置为你想要的高度 */
  overflow: auto; /* 添加滚动条 */
}

table {
  border-collapse: collapse; /* 确保表格的边框合并为单一边框 */
  width: 100%; /* 表格宽度 */
}

td {
  border: 1px solid #ababab; /* 设置单线边框 */
  padding: 6px; /* 单元格内边距 */
}
.el-form-item {
  margin-bottom: 0px;
}
</style>
